<?php

namespace App\Models\Company;
use App\Facades\Site;
use Illuminate\Database\Eloquent\Model;

class CompanyRefreshLog extends Model{
    //设置表的类型和表名
    protected $table='company_refresh_log';
    protected $primaryKey='id';
    protected $guarded = [];
    public $timestamps = false;
    //protected $fillable = [];


    /**
     * 判断是否可以刷新职位
     * @return bool
     */
    public static function isRefresh(){
        $user = auth()->guard('company')->user();
        $getMax=self::getMax();
        if($getMax<0){
            return false;
        }elseif($getMax==0){
            return true;
        }else{
            $count = self::where('refresh_time','>',date('Y-m-d 00:00:00'))->where("uid",$user->uid)->count();
            if($count>=$getMax){
                return false;
            }
            return true;
        }
    }

    /**
     * 返回当前会员今天最大刷新数 -1不能刷新  0不限  正数代表最大次数
     * @return mixed
     */
    public static function getMax(){
        $user = auth()->guard('company')->user();
        if($user->viptime>=date('Y-m-d H:i:s')) {//vip
            return Site::get('vip_refresh_number');
        }else{
            return Site::get('member_refresh_number');
        }
    }

}